var webapi = 'https://demo.jizhicms.cn';
var filepath = 'https://demo.jizhicms.cn'
var apikey = '123456';
function friendlyDate(timestamp) {
	var formats = {
		'year': '%n% 年前',
		'month': '%n% 月前',
		'day': '%n% 天前',
		'hour': '%n% 小时前',
		'minute': '%n% 分钟前',
		'second': '%n% 秒前',
	};

	var now = Date.now();
	var seconds = Math.floor((now - timestamp) / 1000);
	var minutes = Math.floor(seconds / 60);
	var hours = Math.floor(minutes / 60);
	var days = Math.floor(hours / 24);
	var months = Math.floor(days / 30);
	var years = Math.floor(months / 12);

	var diffType = '';
	var diffValue = 0;
	if (years > 0) {
		diffType = 'year';
		diffValue = years;
	} else {
		if (months > 0) {
			diffType = 'month';
			diffValue = months;
		} else {
			if (days > 0) {
				diffType = 'day';
				diffValue = days;
			} else {
				if (hours > 0) {
					diffType = 'hour';
					diffValue = hours;
				} else {
					if (minutes > 0) {
						diffType = 'minute';
						diffValue = minutes;
					} else {
						diffType = 'second';
						diffValue = seconds === 0 ? (seconds = 1) : seconds;
					}
				}
			}
		}
	}
	return formats[diffType].replace('%n%', diffValue);
}

function nowday(){
	var date = new Date();
	return date.toLocaleDateString();
}

function getLocalTime(timestamp){ 
 var date = new Date(parseInt(timestamp)*1000);
 var Y = date.getFullYear() + '-';
 var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
 var D = date.getDate() + ' ';
 var h = date.getHours() + ':';
 var m = date.getMinutes() + ':';
 var s = date.getSeconds(); 
 return (Y+M+D+h+m+s); //呀麻碟
 // 输出结果：2014-04-23 18:55:49

}


export {
	friendlyDate,
	webapi,
	apikey,
	filepath,
	getLocalTime,
	nowday
}
